namespace FIREFLYX {
    export class GlobalEventManager implements IEventListener {
        private static _instance: GlobalEventManager;
        public static get Instance() {
            if (!this._instance) this._instance = new GlobalEventManager();
            return this._instance;
        }

        private _eventDisp = new EventDispatcher();

        public dispatchEvent<K extends keyof IGEventMap>(eventType: K, ev: IGEventMap[K]) {
            return this._eventDisp.dispatch(eventType, ev);
        }

        public addListener<K extends keyof IGEventMap>(eventType: K, listener: (ev: IGEventMap[K]) => any, thisArg: any): void {
            this._eventDisp.on(eventType, listener, thisArg);
        }

        public removeListener<K extends keyof IGEventMap>(eventType: K, listener: any, thisArg: any) {
            this._eventDisp.off(eventType, listener, thisArg);
        }

        public listenerCount<K extends keyof IGEventMap>(eventType: K) {
            return this._eventDisp.listenerCount(eventType);
        }

    }

    interface IGEventMap {
        //-------------------input Events----------------------
        /** 按键按下 */
        "keydown": KeyboardEvent;
        /** 按键弹起 */
        "keyup": KeyboardEvent;
        /** 鼠标按下 */
        "mousedown": MouseEvent;
        /** 鼠标弹起 */
        "mouseup": MouseEvent;
        /** 鼠标移动 */
        "mousemove": MouseEvent;
        /** 鼠标滚轮转动 */
        "mousewheel": WheelEvent;
        /** 鼠标滚轮转动 */
        "DOMMouseScroll": WheelEvent;
        /** 移开焦点 */
        "blur": FocusEvent;
        /** 触摸开始 手指按下*/
        "touchstart": TouchEvent;
        /** 触摸移动 手指移动*/
        "touchmove": TouchEvent;
        /** 触摸结束 手指移开 */
        "touchend": TouchEvent;
        /** 触摸中断 */
        "touchcancel": TouchEvent;
        /** 点击按下 */
        "pointDown": Vector2;
        /** 点击松开 */
        "pointUp": Vector2;
        /** 点击移动 */
        "pointMove": Vector2;
        /** 单击(按下+松开)*/
        "pointClick": Vector2;

        //-------------------asset Events----------------------
        /** 资源加载完成 */
        "assetLoaded": string;
        /** 资源加载失败 */
        "assetLoadFail": string;

        //-------------------normal Events----------------------
        /** 输出画面框改变 */
        "viweFrameChange": string;

        //-------------------scene Events----------------------
        /** 场景Update触发 (deltaTime : number) */
        "sceneUpdate": number;
        /** 场景LateUpdate触发 (deltaTime : number) */
        "sceneLateUpdate": number;

        //-------------------app Events----------------------
        /** 引擎app主循环开始 (deltaTime : number) */
        "appLoopStart": number;
        /** 引擎app主循环结束 (deltaTime : number) */
        "appLoopEnd": number;
    }
}